<?php


namespace suanfa;
//数组去重，考验的是双重循环查找的能力，和退出子循环的能力
$arr = [1,2,3,45,4,3,123,45,5,2];
function ArrayDistinct($arr)
{
    foreach($arr as $r){
        $newArr[$r] = $r;
    }
    return $newArr;
}
function ArrayDistinct2($arr){
    $newArr = [];
    foreach($arr as $r){
        foreach ($newArr as $v){
            if($v == $r){
                $has = true;
                break;
            }
            $has = false;
        }
        if(!$has){
            $newArr[] = $r;
        }
    }
    return $newArr;
}
print_r(ArrayDistinct($arr));

print_r(ArrayDistinct2($arr));